using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace UglyAnimals
{
    class Obstacle:Entity
    {
        public enum ObstacleType {
            Stones,
            Ice,
            Ballon,
            Trampoline
        }

        public ObstacleType Type
        {
            get;
            set;
        }

        public override Vector2 Position
        {
            get;
            set;
        }

        public float MoveSpeed;

        public float Friction
        {
            set;
            get;
        }

        public bool isGroundObstacle
        {
            set;
            get;
        }

        public override int Width
        {
            get
            {
                if (Type == ObstacleType.Ballon)
                {
                    return obstacleAnimation.FrameWidth;
                }
                else
                {
                    return ObstacleTexture.Width;
                }
            }
        }

        public override int Height
        {
           get {
               
               if (Type == ObstacleType.Ballon)
                {
                    return obstacleAnimation.FrameHeight;
                }
                else
                {
                    return ObstacleTexture.Height;
                }
           }
        }

        public Texture2D ObstacleTexture;
        private Animation obstacleAnimation;
        public bool AlreadyIntersected
        {
            get;
            set;
        }


        public Obstacle(ObstacleType type, Texture2D texture)
        {
            Type = type;
            ObstacleTexture = texture;
            switch (Type)
            {
                case ObstacleType.Stones:
                    ObstacleTexture = texture;
                    Friction = 0.95f;
                    isGroundObstacle = true;
                    break;
                case ObstacleType.Ice:
                    ObstacleTexture = texture;
                    Friction = 1.01f;
                    isGroundObstacle = true;
                    break;
                case ObstacleType.Ballon:
                    obstacleAnimation = new Animation();
                    obstacleAnimation.Initialize(ObstacleTexture, new Vector2(), 47, 61, 8, 60, Color.White, 2, true, false);
                    Friction = 1.0f; // no friction at all
                    isGroundObstacle = false;
                    break;
            }
        }

        public void Initialize(Vector2 position, float speed)
        {
            Position = position;
            Active = true;
            MoveSpeed = speed;
            AlreadyIntersected = false;
        }

        public override void Update(GameTime gameTime)
        {
            Position = new Vector2(Position.X - MoveSpeed, Position.Y);
            if (Type == ObstacleType.Ballon)
            {
                obstacleAnimation.Position = Position;
                obstacleAnimation.Update(gameTime);
            }
            if (Position.X < -Width)
            {
                Active = false;
            }
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            if (Active)
            {
                if (Type == ObstacleType.Ballon)
                {
                    obstacleAnimation.Draw(spriteBatch);
                }
                else
                {
                    spriteBatch.Draw(ObstacleTexture, Position, null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
                }
            }
        
        }
    }
}
